package cn.icyzx.service;

import cn.icyzx.dao.DaoTag;
import cn.icyzx.exception.AddWorkTagException;
import cn.icyzx.exception.TagException;
import cn.icyzx.models.Tag;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author zk
 * @Date 2017/3/20.
 * @Email 2117251154@qq.com
 */
@Service
@Transactional
public class TagService {

    private static Logger logger = Logger.getLogger(TagService.class);

    @Autowired
    DaoTag daoTag;

    /*** 通过tagName来获取tag
     *
     * @param tag
     * @return
     */
    public Tag getTagByTagName(String tag) {
        try {
            return daoTag.getTagByName(tag);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return null;
        }
    }

    public List<Tag> getHotTagList() {
        try {
            return daoTag.getTagList();
        } catch (TagException tagExcetion) {
            logger.error("获取hotTagList失败" + tagExcetion.getMessage());
            return null;
        }
    }

    /*** 添加tag
     *
     * @param tag
     * @return
     */
    public void addTag(String tag) {
        try {
            daoTag.addTag(tag);
        } catch (TagException e) {
            logger.error(e.getMessage());
        }
    }

    /*** 为新增的work添加一条tag记录
     *
     * @param wid
     * @param tag
     */
    public void addWorkTagRecord(String wid, String tag) {
        try {
            daoTag.addWorkTagRecord(wid, tag);
        } catch (AddWorkTagException e) {
            logger.error(e.getMessage() + "添加tag记录有错");
        }
    }
}
